package basketMatcher;

import java.util.Vector;

import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MultiHashtable;

import ClassPack.Class;
import algorithms.ClassGrader;

public class Basket {

	
	Vector<Class> m_classes;
	
	private double  mathcing;
	
	public Basket(Vector<Class> classes){
		
		m_classes = classes;
		mathcing = 0;
	}

	public Vector<Class> getM_classes() {
		return m_classes;
	}

	public void setM_classes(Vector<Class> m_classes) {
		this.m_classes = m_classes;
	}

	public double getMathcing() {
		return mathcing;
	}

	public void setMathcing(double mathcing) {
		this.mathcing = mathcing;
	}

	public Double getBasketGrade(Vector<ClassGraderRatio> m_algorithms) {

		double total_average_rating = 0;
		
		for ( ClassGraderRatio cg : m_algorithms){
			ClassGrader class_grader = (cg.getCg());
		
		
		Vector<Class> classes_copy = new Vector<Class>(m_classes );
		double average_rating_per_algorithm = 0;
		
		while (!(classes_copy.size() == 1)) {
			Class first_class = classes_copy.remove(0);
			for (Class  c : classes_copy) {
				
				average_rating_per_algorithm += 
					class_grader.Grade(first_class, c);
				
				System.out.println("grading : " + class_grader.Grade(first_class, c));
				System.out.println("average rating per algorithm" + average_rating_per_algorithm);
			}
		} 
		total_average_rating += average_rating_per_algorithm;
	
	}
		mathcing = total_average_rating;
		
		return total_average_rating;
	}

	/**
	 * @param first_basket
	 * @return true - iff this and first_basket have itersecting classes.
	 */
	public boolean containsClassesFrom(Basket first_basket) {
		
		for (Class c : first_basket.getM_classes()) {
			if ( this.m_classes.contains(c))
				return true;
		}
		
		return false ;
	}
	
	public String toString () {
		return m_classes.toString();
	}
}
